<template>
	<form @submit="submit">
		<view class="cell">
			<view class="cell-title">房号</view>
			<hg-select :clearable="false" :searchable="false" :items="bindeds" v-model="room" class="cell-content"></hg-select>
		</view>
		
		<view class="cell required">
			<view class="cell-title">联系人</view>
			<input class="cell-content" v-model="post.userName" placeholder="请输入联系人姓名"/>
		</view>
		
		<view class="cell required">
			<view class="cell-title">联系电话</view>
			<input class="cell-content" type="number" maxlength="11" v-model="post.phone" placeholder="请输入联系电话"/>
		</view>
		
		<view class="bottom horizontal">
			<button style="color: white;background-color: var(--color-ok);" class="capsule scale" form-type="submit">提交</button>
		</view>
	</form>
</template>

<script>
	import hgCell from '@/components/hg-cell/hg-cell.vue'
	import xflSelect from '@/components/xfl-select/xfl-select.vue'
	import juFieldGroup from '@/components/ju-field/ju-field-group.vue';
	import juField from '@/components/ju-field/ju-field.vue';
	import mkUpload from '@/components/mk-upload/mk-upload.vue'
	import card from '@/mixins/card.js'
	
	const app = getApp()
	
	export default {
		components:{
			hgCell, xflSelect, juFieldGroup, juField, mkUpload, 
		},
		mixins:[card,],
		data() {
			return {
				post:{
					userName:"",
					phone:'',
					code:'',
					// 房号
					roomId: '',
				},
			}
		},
		methods: {
			submit(){
				if(!this.post.userName || !this.post.phone){
					uni.showToast({
						title:'联系人和联系方式必填！',
						icon:'none',
						duration:5000,
					})
					return 
				}
				uni.request({
					header:{
						Authorization: 'Bearer ' + app.globalData.token,
					},
					url: app.globalData.curl + 'workOrder/reportRecovery',
					method: 'POST',
					data: {
						roomId: this.get.rooms[this.room].id,
						remark: this.post.remark,
						userName: this.post.userName,
						phone: this.post.phone,
					},
					success: res => {
						const {data} = res
						console.log(data)
						if(data.code==200){
							uni.showModal({
								title: '恢复用水',
								content: '提交成功，我们工作人员会尽快与您联系！',
								showCancel: false,
								success: res => {
									if(res.confirm){
										uni.redirectTo({
											url: '../progress/progress',
										});
									}
								},
							});
						}else if(data.code==500){
							uni.showToast({
								icon:'none',
								title: data.message,
							});
						}
					},
					fail: (err) => {console.error(err)},
				});
			},
		}
	}
</script>

<style scoped>
	textarea{
		background-color: white;
		border-radius: 10rpx;
	}
</style>
